﻿Imports System.Data.SqlClient
Imports BusinessEntites

Public Class NhanVienDA
    Public Sub New()

    End Sub

    Public Function GetObjectByID(ByVal MA_NV As Integer) As NhanVienObj
        Dim myObj As New NhanVienObj
        Dim arr As New ArrayList
        arr.Add(New SqlParameter("@Ma_NV", MA_NV))
        Dim myDatatable = ExcuteSQL.GetDataSet("NhanVien_SelContentByID", arr).Tables(0)
        If myDatatable.Rows.Count > 0 Then
            myObj.Ma_NV = myDatatable.Rows(0)("Ma_NV")
            myObj.Ma_PB = myDatatable.Rows(0)("Ma_PB")
            myObj.Ma_VT = myDatatable.Rows(0)("Ma_VT")
            myObj.Ten_NV = myDatatable.Rows(0)("Ten_NV")
            myObj.TinhTrang = myDatatable.Rows(0)("TinhTrang")
        End If
        Return myObj
    End Function

    Public Function GetListObject() As ListOfNhanVienObj
        Dim myListObject As New ListOfNhanVienObj
        Dim arr As New ArrayList
        For Each myrow As DataRow In ExcuteSQL.GetDataSet("NhanVien_SelContent").Tables(0).Rows
            Dim myObj As New NhanVienObj
            myObj.Ma_NV = myrow("Ma_NV")
            myObj.Ma_PB = myrow("Ma_PB")
            myObj.Ma_VT = myrow("Ma_VT")
            myObj.Ten_NV = myrow("Ten_NV")
            myObj.TinhTrang = myrow("TinhTrang")
            myListObject.ListOfNhanVienObj.Add(myObj)
        Next
        Return myListObject
    End Function

    Public Function Insert(ByVal myObj As NhanVienObj) As Boolean
        Dim arr As ArrayList
        arr = New ArrayList
        Try
            arr.Add(New SqlParameter("@Ma_NV", myObj.Ma_NV))
            arr.Add(New SqlParameter("@Ma_PB", myObj.Ma_PB))
            arr.Add(New SqlParameter("@Ma_VT", myObj.Ma_VT))
            arr.Add(New SqlParameter("@Ten_NV", myObj.Ten_NV))
            arr.Add(New SqlParameter("@TinhTrang", myObj.TinhTrang))
            arr.Add(New SqlParameter("@ActionName", "insert"))
            ExcuteSQL.ExcuteNonQuery("NhanVien_Man", arr)
            Return True
        Catch
            Return False
        End Try
    End Function

    Public Function Update(ByVal myObj As NhanVienObj) As Boolean
        Dim arr As ArrayList
        arr = New ArrayList
        Try
            arr.Add(New SqlParameter("@Ma_NV", myObj.Ma_NV))
            arr.Add(New SqlParameter("@Ma_PB", myObj.Ma_PB))
            arr.Add(New SqlParameter("@Ma_VT", myObj.Ma_VT))
            arr.Add(New SqlParameter("@Ten_NV", myObj.Ten_NV))
            arr.Add(New SqlParameter("@TinhTrang", myObj.TinhTrang))
            arr.Add(New SqlParameter("@ActionName", "update"))
            ExcuteSQL.ExcuteNonQuery("NhanVien_Man", arr)
            Return True
        Catch
            Return False
        End Try
    End Function

    Public Function Delete(ByVal Ma_NV As Integer) As Boolean
        Dim arr As ArrayList
        arr = New ArrayList
        Try
            arr.Add(New SqlParameter("@Ma_NV", Ma_NV))
            arr.Add(New SqlParameter("@ActionName", "delete"))
            ExcuteSQL.ExcuteNonQuery("NhanVien_Man", arr)
            Return True
        Catch
            Return False
        End Try
    End Function

End Class
